#!/usr/bin/env jruby
# -*- coding: us-ascii -*-
# Elizabeth Wiethoff 2008

require 'java'

########################################

class Integer
  def to_java
    result = java.lang.Long.new self
    return result if result.long_value == self
    raise RangeError, 'integer overflow; recommend Integer#to_big'
  end
  
  def to_big
     java.math.BigInteger.new self.to_s
  end
  
  def Integer.from_java(jnumber)
    unless jnumber.is_a? Java::JavaLang::Number
      raise TypeError, 'not a Java Number'
    end
    jnumber.to_string.to_i
  end
  
  def Integer.from_big(jbiginteger)  # synonym
    Integer.from_java jbiginteger
  end
end

########################################

class Float
  def to_java
    java.lang.Double.new self
  end
  
  def to_big
     java.math.BigDecimal.new self#.to_s
  end
  
  def Float.from_java(jnumber)
    unless jnumber.is_a? Java::JavaLang::Number
      raise TypeError, 'not a Java Number'
    end
    jnumber.to_string.to_f
  end
  
  def Float.from_big(jbigdecimal)  # synonym
    Float.from_java jbigdecimal
  end
end
